ActiveAdmin.register Boss::Order do
  menu label: '管家', parent: '订单'
  actions :index, :show

  index do
    column :order_no
    column :type_i18n
    column '钱包' do |bo|
      link_to(bo.wallet.name || "默认钱包", "/admin/companies/#{bo.wallet.try(:company_id)}/wallets/#{bo.wallet.try(:id)}")
    end
    column :pay_type
    column :total
    column :pay_amount
    column :status_i18n
    column :created_at
    actions
  end

  show do
    attributes_table do
      row :order_no
      row :type_i18n
      row '钱包' do
        link_to(resource.wallet.name || "默认钱包", "/admin/companies/#{resource.wallet.try(:company_id)}/wallets/#{resource.wallet.try(:id)}")
      end
      row :schedule_date
      row '门店' do
        ul style: 'list-style:none;padding: 0' do
          Store.where(id: resource.try(:store_id)).pluck(:name).each do |name|
            li style: 'list-style-type:none;float: left;padding: 1px' do
              name
            end
          end
        end
      end
      row :total
      row :pay_amount
      row :pay_type
      row :status_i18n
      row :created_at
    end
  end

  controller do
    def scoped_collection
      Boss::Order.includes(:wallet)
    end
  end
end
